package com.atguigu.eduservice.controller;


import com.atguigu.commonutils.Response;
import com.atguigu.eduservice.entity.EduChapter;
import com.atguigu.eduservice.entity.EduVideo;
import com.atguigu.eduservice.entity.chapter.ChapterVo;
import com.atguigu.eduservice.service.EduChapterService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author zhaolie
 * @since 2020-12-08
 */
@RestController
@RequestMapping("/eduservice/chapter")
@Api(description = "课程章节")
public class EduChapterController {

    @Resource
    private EduChapterService chapterService;

    // 课程大纲列表
    @GetMapping("/course/{courseId}")
    @ApiOperation("查询章节")
    private Response getChapterVideo(@PathVariable String courseId) {
        List<ChapterVo> chapterList = chapterService.getChapterVideoCourseId(courseId);
        return Response.SUCCESS().data("rows", chapterList);
    }

    // 查询章节
    @GetMapping("/{chapterId}")
    @ApiOperation("查询章节")
    private Response getChapter(@PathVariable String chapterId) {
        EduChapter chapter = chapterService.getChapter(chapterId);
        return Response.SUCCESS().data("rows", chapter);
    }

    // 添加章节
    @PostMapping()
    @ApiOperation("添加章节")
    private Response addChapter(@RequestBody EduChapter eduChapter) {
        chapterService.addChapter(eduChapter);
        return Response.SUCCESS();
    }

    // 修改章节
    @PutMapping()
    @ApiOperation("修改章节")
    private Response updateChapter(@RequestBody EduChapter eduChapter) {
        chapterService.updateChapter(eduChapter);
        return Response.SUCCESS().data("更新成功",null);
    }

    // 删除章节
    @DeleteMapping("/{chapterId}")
    @ApiOperation("删除章节")
    private Response deleteChapter(@PathVariable String chapterId) {
        boolean flag = chapterService.deleteChapter(chapterId);
        if (flag) {
            return Response.SUCCESS();
        }
        return Response.Failed();
    }
}

